package tech.lq0.dreamaticvoyage.item.fukamizutech.material;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import tech.lq0.dreamaticvoyage.init.DamageSourceRegistry;

import java.util.List;

public class MetalBreadSlice extends Item {

    public float hurtDamage = 5.0f;

    public MetalBreadSlice(FoodProperties properties) {
        super(new Item.Properties().fireResistant().food(properties));
    }

    public MetalBreadSlice(float hurtDamage, FoodProperties properties) {
        super(new Item.Properties().fireResistant().food(properties));
        this.hurtDamage = hurtDamage;
    }

    @Override
    public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents, TooltipFlag pIsAdvanced) {
        var description = this.getDescriptionId().split("\\.");
        if (description.length > 2) {
            pTooltipComponents.add(Component.translatable("des.dreamaticvoyage." + description[2]).withStyle(ChatFormatting.GRAY));
        }
    }

    @Override
    public int getUseDuration(ItemStack stack) {
        return 96;
    }

    @Override
    public ItemStack finishUsingItem(ItemStack pStack, Level pLevel, LivingEntity pLivingEntity) {
        if (!pLevel.isClientSide) {
            pLivingEntity.hurt(DamageSourceRegistry.causeFukamizuBreadDamage(pLevel.registryAccess(), null), hurtDamage);
        }
        return super.finishUsingItem(pStack, pLevel, pLivingEntity);
    }
}
